<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:t="http://myfaces.apache.org/tomahawk">

    <f:view>
        <f:loadBundle var="text" basename="#{paymentList.bundleName}"/>
        <head>
            <title>#{text['paymentList.title']}</title>
            <meta name="heading" content="#{text['paymentList.heading']}"/>
            <meta name="menu" content="operationMenu"/>
        </head>
        <body id="paymentList">
        <h:form id="editpayment">

            <h:commandButton value="#{text['button.search']}" action="#{paymentList.execute}" id="search" styleClass="button"/>
            <h:commandButton value="#{text['button.add']}" action="#{paymentForm.add}" id="add" immediate="true" styleClass="button"/>
            <h:commandButton value="#{text['button.done']}" action="mainMenu" id="cancel" immediate="true" styleClass="button" style="margin-left: 5px"/>            

            <h:outputText></h:outputText>
            <h:panelGroup>
                <table>
                    <tr>
                        <td>
                    <t:htmlTag value="div">
                        <h:outputLabel styleClass="desc" for="id" value="#{text['payment.id']}"/>
                        <h:inputText styleClass="text medium" id="id" value="#{paymentList.id}"/>
                        <t:message for="id" styleClass="fieldError"/>
                    </t:htmlTag>
                    </td>
                    <td>
                    <t:htmlTag value="div">
                        <h:outputLabel styleClass="desc" for="description" value="#{text['payment.description']}"/>
                        <h:inputText styleClass="text medium" id="description" value="#{paymentList.description}"/>
                        <t:message for="description" styleClass="fieldError"/>
                    </t:htmlTag>
                    </td>
                    <td>
                    <t:htmlTag value="div">
                        <h:outputLabel styleClass="desc" for="date" value="#{text['payment.date']}"/>
                        <t:inputCalendar id="date" value="#{paymentList.date}" renderAsPopup="true"
                                         popupDateFormat="dd/MM/yyyy" popupTodayString="Hoy es "
                                         popupWeekString="Semana" lang="es">
                        </t:inputCalendar>
                        <t:message for="date" styleClass="fieldError"/>
                    </t:htmlTag>
                    </td>
                    </tr>
                    <tr>
                        <td>
                    <t:htmlTag value="div">
                        <h:outputLabel styleClass="desc" for="company" value="#{text['payment.company']}"/>
                        <h:selectOneMenu value="#{paymentList.company}" id="company" styleClass="select">
                            <f:selectItem itemLabel="Todas"/>
                            <t:selectItems value="#{paymentList.companies}" var="company" itemLabel="#{company.description}" itemValue="#{company}"/>
                            <f:converter converterId="objconverter"/>
                        </h:selectOneMenu>
                        <t:message for="company" styleClass="fieldError"/>
                    </t:htmlTag>
                    </td>
                    <td>
                    <t:htmlTag value="div">
                        <h:outputLabel styleClass="desc" for="status" value="#{text['payment.status']}"/>
                        <h:selectOneMenu value="#{paymentList.stStatus}" id="status" styleClass="select">
                            <f:selectItem itemLabel="Todos"/>
                            <f:selectItem itemLabel="ACTIVO" itemValue="ACTIVO"/>
                            <f:selectItem itemLabel="CANCELADO" itemValue="CANCELADO"/>
                        </h:selectOneMenu>
                        <t:message for="status" styleClass="fieldError"/>
                    </t:htmlTag>
                    </td>
                    </tr>
                </table>
            </h:panelGroup>
            <h:outputText></h:outputText>

            <!-- Error from this table is caused by http://issues.apache.org/jira/browse/TOMAHAWK-466 -->
            <t:dataTable id="payments" var="payment" style="margin-top: 10px"
                         value="#{paymentList.payments}" rows="25" sortColumn="#{paymentList.sortColumn}"
                         sortAscending="#{paymentList.ascending}" styleClass="scrollerTable table"
                         headerClass="standardTable_Header" rowClasses="standardTable_Row1,standardTable_Row2"
                         columnClasses="standardTable_Column,standardTable_Column,standardTable_Column,standardTable_Column,standardTable_ColumnCentered">
                <t:column width="5%">
                    <f:facet name="header">
                        <t:commandSortHeader columnName="id" arrow="true">
                            <h:outputText value="#{text['payment.id']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:commandLink action="#{paymentForm.edit}" value="#{payment.id}">
                        <f:param name="id" value="#{payment.id}"/>
                        <f:param name="from" value="list"/>
                    </h:commandLink>
                </t:column>
                <t:column width="15%">
                    <f:facet name="header">
                        <t:commandSortHeader columnName="company" arrow="true">
                            <h:outputText value="#{text['payment.company']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{payment.company.description}" escape="true"/>
                </t:column>
                <t:column width="20%">
                    <f:facet name="header">
                        <t:commandSortHeader columnName="description" arrow="true">
                            <h:outputText value="#{text['payment.description']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{payment.description}" escape="true"/>
                </t:column>
                <t:column width="10%" title="Fecha">
                    <f:facet name="header">
                        <t:commandSortHeader columnName="date" arrow="true">
                            <h:outputText value="#{text['payment.date']}"/>
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{payment.date}" escape="true">
                        <f:convertDateTime pattern="dd/MM/yyyy"/>
                    </h:outputText>
                </t:column>
                <t:column width="10%">
                    <f:facet name="header">
                        <t:commandSortHeader columnName="type" arrow="true">
                            <h:outputText value="#{text['payment.paymentType']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{payment.type}" escape="true"/>
                </t:column>
                <t:column width="10%">
                    <f:facet name="header">
                        <t:commandSortHeader columnName="receiptNumber" arrow="true">
                            <h:outputText value="#{text['payment.receiptNumber']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{payment.receiptNumber}" escape="true"/>
                </t:column>
                <t:column width="10%" title="#{payment.currency}">
                    <f:facet name="header">
                        <t:commandSortHeader columnName="amount" arrow="true">
                            <h:outputText value="#{text['payment.amount']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{payment.amount}" escape="true">
                        <f:convertNumber type="number" pattern="#,##0.00;(#,##0.00)"/>
                    </h:outputText>
                </t:column>
                <t:column width="10%" title="#{payment.status}">
                    <f:facet name="header">
                        <t:commandSortHeader columnName="status" arrow="true">
                            <h:outputText value="#{text['payment.status']}" />
                        </t:commandSortHeader>
                    </f:facet>
                    <h:outputText value="#{payment.status}" escape="true"/>
                </t:column>
            </t:dataTable>
            <t:saveState id="save1" value="#{paymentList.payments}"/>

            <ui:include src="/common/tableFooter.xhtml">
                <ui:param name="tableName" value="payments"/>
            </ui:include>

            <script type="text/javascript">
                highlightTableRows("editpayment:payments");
            </script>

        </h:form>
    </body>
</f:view>
</html>